<?php

/**
* @copyright   (C) 2010 iJoomla, Inc. - All rights reserved.
* @license  GNU General Public License, version 2 (http://www.gnu.org/licenses/gpl-2.0.html) 
* @author  iJoomla.com webmaster@ijoomla.com
* @url   http://www.ijoomla.com/licensing/
* the PHP code portions are distributed under the GPL license. If not otherwise stated, all images, manuals, cascading style sheets, and included JavaScript  
* are NOT GPL, and are released under the IJOOMLA Proprietary Use License v1.0 
* More info at http://www.ijoomla.com/licensing/
*/

defined('_JEXEC') or die('Restricted Access');
JHtml::_('behavior.tooltip');

include(JPATH_ROOT.DS."administrator".DS."components".DS."com_surveys".DS."left.php");

$document =& JFactory::getDocument();
$document->addStyleSheet("components/com_surveys/css/survey.css");
$document->addScript("components/com_surveys/javascript/survey.js");

$id = JRequest::getVar("id", "0");
$title = "";
$survey_id = "";
$page_id = "";
$question_id = "";
$compare = "";
$answer_value = "";
$action = "";
$logic = "";
$page_target = "";

if(is_array($this->values) && count($this->values)>0){
	$title = $this->values["0"]["title"];
	$survey_id = $this->values["0"]["survey_id"];
	$page_id = $this->values["0"]["page_id"];
	$question_id = $this->values["0"]["question_id"];
	$compare = $this->values["0"]["compare"];
	$answer_value = $this->values["0"]["answer_value"];
	$action = $this->values["0"]["action"];
	$logic = $this->values["0"]["logic"];
	$page_target = $this->values["0"]["page_target"];
}
?>


<script type="text/javascript">
	Joomla.submitbutton = function(pressbutton){
		var ok = true;
		var form = document.adminForm;		
		if (pressbutton == 'cancel') {
			submitform(pressbutton);
		}		
		else if(pressbutton == 'save' || pressbutton == 'apply') {
			var survey = document.adminForm.getElementById("survey_id");
			var index  = survey.selectedIndex;
			var survey_id = survey.options[index].value;			
						
			if (form.title.value == ""){
				alert("Skip Action Name: is a required field.");
				ok = false;
			}			
			if(survey_id == 0){
				alert("Survey name: is a required field.");
				ok = false;
			}
			if(!eval(document.adminForm.getElementById("page_id"))){
				alert("Page name: is a required field.");
				ok = false;
			}
			if(!eval(document.adminForm.getElementById("question_id"))){
				alert("Question Name: is a required field.");
				ok = false;
			}
			if(!eval(document.adminForm.getElementById("answer_value[]"))){
				alert("Answer Value: is a required field.");
				ok = false;
			}
			if(!eval(document.adminForm.getElementById("page_target"))){
				alert("Page: is a required field.");
				ok = false;
			}										
			if(ok){
				submitform( pressbutton );		
			}	
		}
		else{
			submitform( pressbutton );
		}
		
	}
</script>

<form action="index.php" method="post" name="adminForm" id="adminForm">
	
	<table width="100%" >
		<tr>
			<td>
				<h2 style="color:#669900"><img src="<?php echo JUri::base(); ?>/components/com_surveys/images/icons/skip_actions.png" width="48" height="48"  align="middle" />
				<?php 
				if($id != "0" ) {
					echo " " . JText::_("COM_SURVEYS_EDIT_SKIP_ACTION") . "</h2>";
				}
				else{
					echo " " . JText::_("COM_SURVEYS_NEW_SKIP_ACTION") . "</h2>";
				}				
				?>
			</td>
			<td align="right">
				<a class="video" href="http://www.ijoomla.com/redirect/survey/videos/skip.htm" target="_blank">Video Tutorial <img src="components/com_surveys/images/icon_video.gif"></a>
			</td>			
		</tr>	
	</table>
	
	<table width="100%" class="adminform">
		<tr style="margin-top:5px; margin-bottom:5px;">
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_SKIP_ACTION_NAME");?>:<span style="color:#FF0000">*</span></b>
			</td>
			<td align="left">
				<?php
					$title = str_replace('"', "&quot;", $title);
				?>
				<input type="text" name="title" value="<?php echo $title; ?>" size="50">
			</td>
		</tr>
		<tr style="margin-top:5px; margin-bottom:5px;">
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_SURVEY_NAME");?>:<span style="color:#FF0000">*</span></b>
			</td>
			<td align="left">
				<?php 
					echo $this->getSurveysList($survey_id);
				?>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_PAGE_NAME");?>:<span style="color:#FF0000">*</span></b>
			</td>
			<td align="left">
				<div id="page_skip">
				<?php
					if($id != "0"){ 
						echo $this->getPageList($page_id, $survey_id);
					}
					else{
						echo "<b><span style=\"color: red;\">".JText::_("COM_SURVEYS_SELECT_SURVEY_NAME")."</span></b>";
					}
				?>
				</div>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_QUESTION_NAME");?>:<span style="color:#FF0000">*</span></b>
			</td>
			<td align="left">
				<div id="question_skip">
				<?php
					if($id != "0"){ 
						echo $this->getQuestionList($question_id, $survey_id);
					}
					else{
						echo "<b><span style=\"color: red;\">".JText::_("COM_SURVEYS_SELECT_SURVEY_NAME")."</span></b>";
					}
				?>
				</div>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_COMPARE");?>:</b>
			</td>
			<td align="left">
				<select name="compare">
					<option value="equal" <?php if($compare=="equal"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_EQUAL"); ?></option>
					<option value="different" <?php if($compare=="different"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_DIFFERENT"); ?></option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%" valign="top">
				<b><?php echo JText::_("COM_SURVEYS_ANSWER_VALUE");?>:<span style="color:#FF0000">*</span></b><br/>
				<b><?php echo JText::_("COM_SURVEYS_LOGIC"); ?>:</b>&nbsp;
				<select name="logic">
					<option value="OR" <?php if($logic=="OR"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_OR"); ?></option>
					<option value="AND" <?php if($logic=="AND"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_AND"); ?></option>
				</select>
			</td>
			<td align="left">
				<div id="answers_skip">
				<?php
					if($id != "0"){
						echo $this->getAnswerValues($answer_value, $question_id); 						
					}
					else{
						echo "<b><span style=\"color: red;\">".JText::_("COM_SURVEYS_SELECT_QUESTION_NAME")."</span></b>";
					}
				?>
				</div>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_ACTION");?>:</b>
			</td>
			<td align="left">
				<select name="action">
					<option value="jump to" <?php if($action=="jump to"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_JUMP_TO"); ?></option>
					<option value="skip" <?php if($action=="skip"){echo 'selected="selected"';} ?> ><?php echo JText::_("COM_SURVEYS_SKIP"); ?></option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left" width="13%">
				<b><?php echo JText::_("COM_SURVEYS_PAGE");?>:<span style="color:#FF0000">*</span></b>
			</td>
			<td align="left">
				<div id="page_target_skip">
				<?php
					if($id == "0"){
						echo "<b style=\"color:red;\">".JText::_("COM_SURVEYS_SELECT_SURVEY_PAGE")."</b>";
					}
					else{
						echo $this->getPageTarget($survey_id, $page_id, $page_target);
					}
				?>
				</div>
			</td>
		</tr>
	</table>	
	
	<input type="hidden" name="option" value="com_surveys" />
	<input type="hidden" name="controller" value="newskip" />
	<input type="hidden" name="task" value="" />
	<input type="hidden" name="boxchecked" value="0" />
	<input type="hidden" name="id" value="<?php echo $id; ?>" />
	<?php echo JHtml::_('form.token'); ?>
</form>

</td></tr></table>
<p><center><?php echo JText::_("COM_IJOOMLA_SURVEYS_POWERED_BY") ; ?>&nbsp;<a href='http://www.ijoomla.com' target='_blank'><?php echo JText::_("COM_SURVEYS_SURVEY"); ?></a></center></p>	